python 文件 io
以下代码演示了python基本的文件操作,包括 open,read,write:
实例(python 3.0+)
# filename : test.py # author by : www.51frw.cn # 写文件 with open("test.txt", "wt") as out_file:
out_file.write("该文本会写入到文件中n看到我了吧!") # read a file with open("test.txt", "rt") as in_file:
text = in_file.read() print(text)
执行以上代码输出结果为:
该文本会写入到文件中 看到我了吧!
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!